package com.lzs.baseruku.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzs.baseruku.mapper.CommodityMapper;
import com.lzs.baseruku.service.CommodityService;
import com.lzs.entity.Commodity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author ymx
 * @since 2020-11-23
 */
@Service
public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity> implements CommodityService {

    @Override
    public Page<Commodity> findCommodity(Integer page, Integer limit, Commodity commodity) {
        Page<Commodity> pageInfo=new Page<>(page,limit);
        String bar=commodity.getBar();
        String name=commodity.getName();
        String alias=commodity.getAlias();
        Long warehouseid=commodity.getWarehouseid();
        QueryWrapper queryWrapper=new QueryWrapper();
        if (StringUtils.isNotEmpty(bar)){
            queryWrapper.like("bar",bar);
        }
        if (StringUtils.isNotEmpty(name)){
            queryWrapper.like("name",name);
        }
        if (StringUtils.isNotEmpty(alias)){
            queryWrapper.like("alias",alias);
        }
        if (warehouseid!=null){
            queryWrapper.like("warehouseid",warehouseid);
        }
        this.baseMapper.selectPage(pageInfo,queryWrapper);
        return pageInfo;
    }
}
